var Redis = require('ioredis');
var client = null;

if(process.env.RUN_ENV === 'ONLINE' && process.env.IS_TEST !== 'Y'){
    client = new Redis({
        port : 6379 ,
        host : 'r-2zedf165pv201jcjw4.redis.rds.aliyuncs.com',
        password: 'TPxu234@#$'
    });
}
else{
    client = new Redis.Cluster([
        { port : 20001 , host : '127.0.0.1'},
        { port : 20003 , host : '127.0.0.1'},
        { port : 20005 , host : '127.0.0.1'}
    ]);
}


client.on("error", function (err) {
    console.log("Redis Error has occured : " + err);
});

client.on("connect", function (err) {
    console.log("Redis has connected to server!");
});

process.on('SIGINT', function() {
    console.log('Redis connection disconnected through app termination');
    client.quit();
    process.exit(0);
});

module.exports = client;